# 创建自定义异常类，继承自内置的异常类（通常是 Exception 或其子类）
class MyException(Exception):
    def __init__(self, msg):
        super().__init__(msg)
        self.msg = msg

try:
    raise MyException('自定义异常')
except MyException as e:
    print(e)